tool
class_name Multi, "res://ecs/icons/multi.svg"
extends Notify

export(Resource) var resource

var data := {}


func _init(_name = ""):
	if _name:
		self.name = _name


func _ready():
	if not resource:
		return
	if Engine.editor_hint:
		self.name = "Multi<%s>" % resource.get("component_name")
	else:
		self.name = resource.get("component_name")  #same name with resource


func insert(id, component) -> void:
	var old = data.get(id)
	data[id] = component

	component._notify = self
	component._id = id

	if old:
		modify_event(id, "")
	else:
		create_event(id)


func get(id):
	return data.get(id)


func destroy(id) -> void:
	var component = data.get(id)
	if component:
		destroy_event(id)
		var state = data.erase(id)
		print("destroy", state)
